package com.zhuanzhuan.hero.user.mq.producer;

import com.alibaba.rocketmq.client.producer.SendResult;
import com.alibaba.rocketmq.client.producer.SendStatus;
import com.bj58.youpin.common.utils.json.JsonUtils;
import com.zhuanzhuan.hero.user.mq.dto.*;
import com.zhuanzhuan.hunter.mq.producer.anno.HunterProducer;
import com.zhuanzhuan.hunter.mq.producer.inter.IHunterProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @ClassName HeroUserProducer
 * @Description
 * @Author hanjunjun
 * @Date 2024/7/10 15:26
 */
@Component
@Slf4j
public class HeroUserProducer {

    @HunterProducer(topic = "userInfoChangeTopic", group = "userInfoChangeTopicSenderGroup")
    private IHunterProducer heroUserSender;

    @HunterProducer(topic = "hero_user_cancel_account", group = "userCancelAccountSenderGroup")
    private IHunterProducer userCancelAccountSender;

    public boolean sendPersonInfoPerfection(BaseUserMsg body) {
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendPersonInfoPerfection msg={}", msg);
        SendResult sendResult = heroUserSender.send("infoPerfection", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendUserRegist(UserRegistMsg body) {
//        return true;
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendUserRegist msg={}", msg);
        SendResult sendResult = heroUserSender.send("regist", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendBaseInfoUpdate(UserBaseInfoMsg body) {
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendBaseInfoUpdate msg={}", msg);
        SendResult sendResult = heroUserSender.send("baseInfo", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendContactInfoUpdate(UserInfoUpdateMsg body) {
        body.setType("contactWay");
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendContactInfoUpdate msg={}", msg);
        SendResult sendResult = heroUserSender.send("contactInfo", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendAuthenticationInfoUpdate(BaseUserMsg body) {
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendAuthenticationInfoUpdate msg={}", msg);
        SendResult sendResult = heroUserSender.send("authenticationInfo", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendBusinessLabelUpdate(BaseUserMsg body) {
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendBusinessLabelUpdate msg={}", msg);
        SendResult sendResult = heroUserSender.send("businessLabel", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendAdvantagesLabelUpdate(BaseUserMsg body) {
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendAdvantagesLabelUpdate msg={}", msg);
        SendResult sendResult = heroUserSender.send("advantagesLabel", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendUnregistUpdate(BaseUserMsg body) {
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendUnregistUpdate msg={}", msg);
        SendResult sendResult = heroUserSender.send("unregistered", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendReliableNumUpdate(BaseUserMsg body) {
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendReliableNumUpdate msg={}", msg);
        SendResult sendResult = heroUserSender.send("reliableNum", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendFraternityAuthNumUpdate(BaseUserMsg body) {
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendFraternityAuthNumUpdate msg={}", msg);
        SendResult sendResult = heroUserSender.send("fraternityAuthNum", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }

    public boolean sendBackBusinessLabelUpdate(BackBusinessLabelUpdateMsg body) {
        String msg = JsonUtils.toJsonWithoutNull(body);
        log.info("sendBackBusinessLabelUpdate msg={}", msg);
        SendResult sendResult = heroUserSender.send("backBusinessLabel", msg);
        log.info("sendResult={}", JsonUtils.toJsonWithoutNull(sendResult));
        return sendResult != null && SendStatus.SEND_OK.equals(sendResult.getSendStatus());
    }
}
